package cl.utfsm.android;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.RadioButton;
import android.widget.CompoundButton;

public class RadioActivity extends Activity {
	
	int resultado=0;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		
		//Inicializacion de variables
		
		super.onCreate(savedInstanceState);
		setContentView(R.layout.radio);	
		
		RadioButton Opcion1 = (RadioButton)findViewById(R.id.radio1);
		RadioButton Opcion2 = (RadioButton)findViewById(R.id.radio2);
		RadioButton Opcion3 = (RadioButton)findViewById(R.id.radio3);
		RadioButton Opcion5 = (RadioButton)findViewById(R.id.radio5);
		RadioButton Opcion6 = (RadioButton)findViewById(R.id.radio6);
		RadioButton Opcion7 = (RadioButton)findViewById(R.id.radio7);
		
			
		;
        

	    Button btn = (Button) findViewById(R.id.Btnradio);    
	    btn.setOnClickListener(new View.OnClickListener() {
			
			public void onClick(View v) {
				
				  //aca le damos el valor el radio a utilizar
		        Intent in = new Intent();
		        setResult(resultado,in);
		        finish();

				
			}
		});
	
	// Funciones onchange del RadioButton (radio de alcanze de la aplicacion)
		
		Opcion1.setOnCheckedChangeListener(new RadioButton.OnCheckedChangeListener(){
	
			public void onCheckedChanged(CompoundButton buttonView,
					boolean isChecked) {
				if(isChecked){
				resultado=2;	
				}	
			}}
		);
		
		
		Opcion2.setOnCheckedChangeListener(new RadioButton.OnCheckedChangeListener(){
	
			public void onCheckedChanged(CompoundButton buttonView,
					boolean isChecked) {
				if(isChecked){
				resultado=3;	
				}
			}}
		);
		
		
		Opcion3.setOnCheckedChangeListener(new RadioButton.OnCheckedChangeListener(){
	
			public void onCheckedChanged(CompoundButton buttonView,
					boolean isChecked) {
					if(isChecked){
					resultado=4;
					}
					
			}}
		);
		
				
		Opcion5.setOnCheckedChangeListener(new RadioButton.OnCheckedChangeListener(){
	
			public void onCheckedChanged(CompoundButton buttonView,
					boolean isChecked) {
				if(isChecked){
				resultado=5;	
				}
			}}
		);
			
		
		Opcion6.setOnCheckedChangeListener(new RadioButton.OnCheckedChangeListener(){
	
			public void onCheckedChanged(CompoundButton buttonView,
					boolean isChecked) {
				if(isChecked){
				resultado=6;	
				}
				
			}}
		);
			
		
		Opcion7.setOnCheckedChangeListener(new RadioButton.OnCheckedChangeListener(){
	
			public void onCheckedChanged(CompoundButton buttonView,
					boolean isChecked) {
				if(isChecked){
				resultado=7;	
				}
				
			}}
		);
			
			
		}
}